import request from '@/utils/request';
import qs from 'qs'
export async function queryRule(params) {
  const limit = params.pageSize;
  const page = params.current;
  const my_params = {
    limit: limit,
    page: page,
  };
  Object.assign(params, my_params);
  delete params.current;
  delete params.pageSize;
  return request('/pay/order/page2', {
    params:params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  });
}
export async function removeRule(id) {
  return request(`/pay/order/${id}`, {
    method: 'DELETE',
    data: {},
  });
}
export async function addRule(params) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'post',
    },
  });
}
export async function updateRule(params) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}
export async function getPayOrder(params) {
  return request(`pay/order/${params}`, {
    method: 'GET',
  });
}
export async function BackOrder(params) {
  return request(`member/recordRefund/deal`, {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
export async function BackOrderByWechat(params) {
  return request(`member/recordRefund/deal/wechat`, {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
export async function storeList(params) {
  return request(`/store/store/list`, {
    params,
  });
}
export async function storeBaseList(params) {
  return request(`/store/store/baseList`, {
    params,
  });
}
export async function exportOrder({
  type,
  status,
  startPayTime,
  endPayTime,
  memberNumber
}) {
  return request(
    memberNumber && status ?
    `/pay/order/excel/exportOrder?type=${type}&startPayTime=${startPayTime}&endPayTime=${endPayTime}&status=${status}&memberNumber=${memberNumber}` :
    memberNumber && !status ?
    `/pay/order/excel/exportOrder?type=${type}&startPayTime=${startPayTime}&endPayTime=${endPayTime}&memberNumber=${memberNumber}` :
    !memberNumber && status ?
    `/pay/order/excel/exportOrder?type=${type}&startPayTime=${startPayTime}&endPayTime=${endPayTime}&status=${status}` :
    `/pay/order/excel/exportOrder?type=${type}&startPayTime=${startPayTime}&endPayTime=${endPayTime}`, {
      method: 'GET',
      responseType: 'blob',
    },
  );
}
export async function exportOrderByStores(params) {
  return request(
    `/pay/order/excel/exportOrder`, {
      params:params,
      paramsSerializer: params => {
        return qs.stringify(params, { indices: false })
      },
      method: 'GET',
      responseType: 'blob',
    },
  );
}
export async function rectifyIntegral(data) {
  return request('pay/order/rectifyIntegral', {
    method: 'POST',
    data
  });
}
